Fix a regression of bug 4899 due to HHPv2: <h> tags now appear on tree depth levels...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 1 Feb 2008 01:35:55 +0000 (01:35 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 1 Feb 2008 01:35:55 +0000 (01:35 +0000)
The implications in general are that headings inside properly-closed double braces will not have section edit links, even where the braces are broken by invalid title characters and expanded literally to recover the heading. Respecting such headings as section breaks would run into the same problems as those discussed w.r.t. LST on wikitech-l -- there's no way to recover the text for a section that starts on one tree level and finishes on a different one. The fact that higher level <h> nodes appear in the XML is just due to a shortcut in preprocessToObj(): headings are put into the stack in case the braces turn out to be unclosed, in which case the heading will be at level 1 of the tree.

includes/Parser.php
includes/Preprocessor_DOM.php

index 5f56c0d..418792a 100644 (file)
@@ -4572,7 +4572,6 @@ class Parser
                $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode
                $this->mOptions = new ParserOptions;
                $this->setOutputType( self::OT_WIKI );
-               $curIndex = 0;
                $outText = '';
                $frame = $this->getPreprocessor()->newFrame();
 
@@ -4597,22 +4596,19 @@ class Parser
                        // Section zero doesn't nest, level=big
                        $targetLevel = 1000;
                } else {
-                       while ( $node ) {
-                               if ( $node->getName() == 'h' ) {
-                                       if ( $curIndex + 1 == $sectionIndex ) {
+            while ( $node ) {
+                if ( $node->getName() == 'h' ) {
+                    $bits = $node->splitHeading();
+                                       if ( $bits['i'] == $sectionIndex ) {
+                                       $targetLevel = $bits['level'];
                                                break;
                                        }
-                                       $curIndex++;
                                }
                                if ( $mode == 'replace' ) {
                                        $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
                                }
                                $node = $node->getNextSibling();
                        }
-                       if ( $node ) {
-                               $bits = $node->splitHeading();
-                               $targetLevel = $bits['level'];
-                       }
                }
 
                if ( !$node ) {
@@ -4627,10 +4623,9 @@ class Parser
                // Find the end of the section, including nested sections
                do {
                        if ( $node->getName() == 'h' ) {
-                               $curIndex++;
                                $bits = $node->splitHeading();
                                $curLevel = $bits['level'];
-                               if ( $curIndex != $sectionIndex && $curLevel <= $targetLevel ) {
+                               if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) {
                                        break;
                                }
                        }
index 0fa48c4..0cd9df3 100644 (file)
@@ -955,7 +955,11 @@ class PPFrame_DOM implements PPFrame {
                                        # Heading
                                        $s = $this->expand( $contextNode->childNodes, $flags );
 
-                                       if ( $this->parser->ot['html'] ) {
+                    # Insert a heading marker only for <h> children of <root>
+                    # This is to stop extractSections from going over multiple tree levels
+                    if ( $contextNode->parentNode->nodeName == 'root' 
+                      && $this->parser->ot['html'] ) 
+                    {
                                                # Insert heading index marker
                                                $headingIndex = $contextNode->getAttribute( 'i' );
                                                $titleText = $this->title->getPrefixedDBkey();